<?php

/**
 * recipient actions.
 *
 * @package    25Mails
 * @subpackage recipient
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class recipientActions extends sfActions {

    public function executeIndex(sfWebRequest $request) {
        $this->recipients = Doctrine::getTable('Recipient')
                        ->createQuery('a')
                        ->execute();
    }

    public function executeShow(sfWebRequest $request) {
        $this->recipient = $this->getRoute()->getObject();
        $this->forward404Unless($this->recipient);
    }

    /**
     * Count the target recipients for the campaign
     * @param sfWebRequest $request
     */
    public function executeCountrecipientfilter(sfWebRequest $request) {
        if ($request->isXmlHttpRequest()) {
            $rfilter = $request->getParameter('recipientsfilter');
            $tfilter = $request->getParameter('tagsfilter');
            $q = Doctrine_Core::getTable('Recipient')->getTargetRecipientsQuery($rfilter, $tfilter);
            $recipientsNum = $q->count();

            $server_output = $recipientsNum . ' recipient(s) for this filter';

            return $this->renderText($server_output);
        }
        return $this->renderText("Bad Request");
    }

}
